import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Mysqlthree {
    public static void main(String[] args) {
        Connection con;
        Statement sql;
        ResultSet rs;
        con = GetDBConnection.connectDB("world", "root", "");
        if (con == null) {
            return;
        }
        String sqlStr = "select Name,LifeExpectancy from country order by LifeExpectancy";
        try {
            sql = con.createStatement();
            rs = sql.executeQuery(sqlStr);
            while (rs.next()) {
                float life = rs.getInt(2);
                String name = rs.getString(1);
                rs.first();
                while (life == 0) {
                    rs.next();
                    life = rs.getInt(2);
                }
                name = rs.getString(1);
                System.out.println("世界上平均寿命最短的国家为：" + name);
                rs.last();
                name = rs.getString(1);
                System.out.println("世界上平均寿命最长的国家为：" + name);

            }
        } catch (SQLException e) {
            System.out.println("Error:" + e);
        }
    }
}